# -*- coding:utf-8 -*-
import uuid
from fastapi import APIRouter, Request, Depends, Query
from core.response import tableinfo, success, fail
from core.curd import IDList
from app.service.system import SysMenuService
from core.utils import TreeUtil
from app.entity.system import CreateSysMenu, UpdateSysMenu
from app.annotation import CacheAble

router = APIRouter()


@router.get("/authority")
async def authority():
    return success("ok", ["*"])


@router.get("/nav")
async def nav(req: Request, mService=Depends(SysMenuService.instance)):
    ret = await mService.get_menu_tree()
    return success("ok!", TreeUtil.build_tree_nodes(ret))


@router.get("/all")
async def allmenu(mService=Depends(SysMenuService.instance)):
    ret = await mService.get_menu_tree()
    return success("ok!", TreeUtil.build_tree_nodes(ret))


@router.get("/list")
async def lists(mService=Depends(SysMenuService.instance)):
    ret = await mService.get_menu_tree()
    return success("ok!", TreeUtil.build_tree_nodes(ret))


@router.post('/add')
async def add(post: CreateSysMenu, mService=Depends(SysMenuService.instance)):
    """
        添加测试
    """
    one = await mService.insert(post.dict())
    return success('OK', one)


@router.post('/edit')
async def update(post: UpdateSysMenu, mService=Depends(SysMenuService.instance)):
    """
        编辑测试
    """
    one = await mService.update(post.dict())
    return success('OK', one)


@router.post('/del')
async def remove(ids: IDList, mService=Depends(SysMenuService.instance)):
    """
        删除测试
    """
    one = await mService.delete_batch_ids(ids.ids)
    return success('OK')
